<?php if(! defined('HAS_POWER') ) exit('无权访问!');
/**
==============================================================================
 * Class Controller GracePHP的核心数据库实例类
 * @author 肖永标
 * @date 2014-12-14
==============================================================================
 */
class DB {

    private static $pdo = null;

    private function __construct(){}
    private function __clone() {}

    public static function getInstance()
    {
        $user = Config::getItem('db.user');
        $host = Config::getItem('db.host');
        $pass = Config::getItem('db.pass');
        $dbName = Config::getItem('db.name');
        $charSet = Config::getItem('db.charset');

        $dsn = 'mysql:dbname='.$dbName.';host='.$host.'';

        if(!self::$pdo instanceof PDO)
        {
            try {
                self::$pdo = new PDO($dsn, $user, $pass);
            } catch (PDOException $e) {
                echo $e->getMessage();
            }
        }
        
        self::$pdo->query('set names ' . $charSet);
        return self::$pdo;
    }
}

